
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<link rel="stylesheet" href="css/bootstrap-3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/register.css" />
<link rel="stylesheet" href="css/listCommon.css" />
<link rel="stylesheet" href="css/evaluation.css" />
<%-- 导入面包屑 --%>
<jsp:include page="../common/nav.jsp"></jsp:include>
<style>
	.saveBtn{
		background: #2c74fa;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.btnBack{
		background: #ddd;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.select2-container {
		width: calc(100vw / 2 - 240px) !important;
	}
	.select2-container span:nth-child(1) {
		color: #999;
	}
</style>

<div class="wrapper wrapper-content animated fadeInRight">

	<%-- 导入提示信息框 --%>
    <c:if test="${hint!=null&&hint!=''}">
   		<jsp:include page="../common/alert/alert.jsp">
   			<jsp:param value="${hint}" name="alertType"/>
   			<jsp:param value="${alertMessage}" name="alertMessage"/>
   		</jsp:include>
    </c:if>

	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
				<div class="ibox-title">
					<h4>物料编辑</h4>
					<div class="ibox-tools">
					</div>
				</div>

				<div class="ibox-content">
					<form id="editForm" action="web/mdMaterial/editMdMaterial" method="post">
					
					<div class="tabs-container">

						<div id="tabDiv" class="tab-content">

						<!-- mainTab开始 -->
						<div id="mainTab" class="tab-pane active">
						<div class="panel-body" style="padding-bottom: 0px; border-bottom: 0px;">
						
						<div class="row">
							<div class="col-md-6">
								<div class="form-group">
									<span>*</span>
									<label>物料/服务：</label>
									<select name="materialType" id="materialType" class="form-control">
										<option value="" selected="">请选择</option>
										<c:forEach items="${requestScope.materialTypeMap}" var="materialType">
											<option value="${materialType.key}">${materialType.value}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="col-md-6">
								<div class="form-group">
									<span>*</span>
									<label>物料类别：</label>
									<input id="categoryDesc" type="text" class="form-control" value="${requestScope.mdMaterial.categoryDesc}" readonly="readonly">
									<input id="categoryCode" name="categoryCode" type="hidden" class="form-control" value="${requestScope.mdMaterial.categoryCode}">
								</div>
							</div>
							<div class="col-md-6">
								<div class="form-group">
									<span>*</span>
									<label>物料编码：</label>
									<input id="materialCode" name="materialCode" type="text" class="form-control" value="${requestScope.mdMaterial.materialCode}">
								</div>
							</div>
							<div class="col-md-6">
								<div class="form-group">
									<span>*</span>
									<label>物料名称：</label>
									<input id="materialName" name="materialName" type="text" class="form-control" value="${requestScope.mdMaterial.materialName}">
								</div>
							</div>

							<div class="col-md-6">
								<div class="form-group">
									<span>&nbsp</span>
									<label>规格型号</label>
									<input id="standard" name="standard" type="text" class="form-control" value="${requestScope.mdMaterial.standard}">
								</div>
							</div>
							<div class="col-md-6">
								<div class="form-group">
									<span>&nbsp</span>
									<label>品牌</label>
									<input id="brand" name="brand" type="text" class="form-control" value="${requestScope.mdMaterial.brand}">
								</div>
							</div>
							<div class="col-md-6">
								<div class="form-group">
									<span>&nbsp</span>
									<label>单位</label>
									<select name="materialUnit" id="materialUnit" class="select2 form-control" style="width:calc(100vw / 2 - 240px);">
										<option value="" selected="">请选择</option>
										<c:forEach items="${requestScope.materialUnitMap}" var="materialUnit">
											<option value="${materialUnit.key}">${materialUnit.value}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="col-md-6">
								<div class="form-group">
									<span>&nbsp</span>
									<label>供应商</label>
									<input id="supplier" name="supplier" type="text" class="form-control" value="${requestScope.mdMaterial.supplier}">
								</div>
							</div>
							<div class="col-md-6">
								<div class="form-group">
									<span>&nbsp</span>
									<label>备注</label>
									<input id="remark" name="remark" type="text" class="form-control" value="${requestScope.mdMaterial.remark}">
								</div>
							</div>
							<div class="col-md-6">
								<div class="form-group">
									<span>*</span>
									<label>状态</label>
									<select class="form-control m-b" name="status" id="status">
										<option value="Y" selected="selected">有效</option>
										<option value="N">无效</option>
									</select>
								</div>
							</div>
							<div class="col-sm-12">
								<div class="text-right">
									<button class="btn btnBack" type="button" onclick="window.location.href='web/mdMaterial/getMdMaterialList'">返回</button>
									<button class="btn saveBtn" data-style="expand-right">保存</button>
								</div>
							</div>
						</div>
							<input type="hidden" name="materialId" value="${requestScope.mdMaterial.materialId}">
							<input type="hidden" name="createdDate" value="${requestScope.mdMaterial.createdDate}">
							<input type="hidden" name="createdBy" value="${requestScope.mdMaterial.createdBy}">

						</div>
						</div>
						<!-- mainTab结束 -->


						
						</div>
					</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 导入物料类型选择框 -->
<jsp:include page="pop/materialCategoryTreeModal.jsp"></jsp:include>

<!-- select2 -->
<script src="js/plugins/select2/select2.full.min.js"></script>

<script>
	$(document).ready(function() {
	    $(".select2-container--default").css("width", "200");
		//初始化status
		if("${requestScope.mdMaterial.status}"!=""){
			$("#status").val("${requestScope.mdMaterial.status}");
		}
		//初始化materialType
		if("${requestScope.mdMaterial.materialType}"!=""){
			$("#materialType").val("${requestScope.mdMaterial.materialType}");
		}
		//初始化materialUnit
		if("${requestScope.mdMaterial.materialUnit}"!=""){
			$("#materialUnit").val("${requestScope.mdMaterial.materialUnit}");
		}

		//初始化code只读
		if("${requestScope.mdMaterial.materialId}"!=""){
			$("#materialCode").prop("readonly", true);
		}
		
		//初始化select2
		$('.select2').select2({width: "100%"});
		
		//物料类型选择框
		$("#categoryDesc").focus(function(){
			$('#treeDiv').modal('show');
			$(".modal-backdrop").remove();
		});

		//表单处理
		var l = $('.ladda-button-demo').ladda();

		l.click(function() {
			$("#editForm").valid();
			//l.ladda('stop');
		});

		$("#editForm").validate({
			rules : {
				materialType : {
					required : true,
				},
				materialCode : {
					required : true,
					isCode : true,
				},
				materialName : {
					required : true,
				},
				categoryCode : {
					required : true,
				},
				/*
				materialUnit : {
					required : true,
				},
				standard : {
					required : true,
				},
				standardUnit : {
					required : true,
				},
				*/
			},
			submitHandler: function(form) {
				var submitFlag = "Y";
				
				//字段验证
				if($("#materialType").val()=="MATERIAL"){
					if($("#materialUnit").val()==""){
						redragonJS.alert("物料单位不能为空");
						submitFlag = "N";
					}else if($("#standard").val()==""){
						redragonJS.alert("规格不能为空");
						submitFlag = "N";
					}
				}
				

				if(submitFlag=="Y"){
					l.ladda('start');
		        	form.submit();
				}
				
		    }
		});
	});

</script>